﻿@using  RooHui.Infrastructure.Entities.Entity;
@using RooHui.Tool;
@{
    ViewBag.Title = "流程节点定义";
    Layout = "~/Views/Shared/_Base.cshtml";
   ProcessDef processDef = ViewBag.processDef; 
    
}
@section head{
    <script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.validate.min.js")"></script>
    <script src="@Url.Content("~/Content/roohui/jquery-validation/jquery.metadata.js")"></script>
    <script src="@Url.Content("~/Content/roohui/jquery-validation/messages_cn.js")"></script> 
    <script src="@Url.Content("~/Content/operate/processpromanage.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var singtypedata = [
                { id: 0, name: '单一审批' },
                { id: 1, name: '多人并行审批' },
                { id: 2, name: '多人审批一人认可' }
                 
                ];
            $("#signtyperadio").ligerRadioList({
                data: singtypedata,
                textField: 'name'
            });

//            var changestatusdata = [ 
//                { id: 1, name: '审核中' },
//                { id: 2, name: '审核完成' }

//                ];
//            $("#changestatusradio").ligerRadioList({
//                data: changestatusdata,
//                textField: 'name'
//            });

            $("#singUser").ligerComboBox(
                {
                    url: '/User/GetActiveUser',
                    valueField: 'UserName',
                    textField: 'RealName', 
                    autocomplete: true
                }
            );
                liger.get("signtyperadio").setValue(0);
               // liger.get("changestatusradio").setValue(2);
        });
    </script>
}
<div id="toptoolbar" style="width: 100%">
</div> 
<div id="processgrid">
</div>
<input type="hidden" name="processdefID" id="processdefID" value="@processDef.ID" />
<form action="/" method="post" id="frmProcess" name="frmProcess" style="background-color: white;
display: none">
    <table cellpadding="0" cellspacing="0" class="l-table-edit" width="100%">
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;节点名称:
            </td>
            <td align="left" class="l-table-edit-td" >
             
                <input name="txtProcessName" type="text" id="txtProcessName" class="l-text-field" validate="{required:true}"/>
               
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;会签类型:
            </td>
            <td align="left" class="l-table-edit-td">
                   <div id="signtyperadio" ></div>
            </td>
            <td align="left">
            </td>
        </tr>
        <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;审批人:
            </td>
            <td align="left" class="l-table-edit-td">
                  <input type="text" id="singUser" class="l-text-field" validate="{required:true}"/> 
            </td>
            <td align="left">
            </td>
        </tr>
        @* <tr>
            <td align="right" class="l-table-edit-td">
                <span class="l-star">*</span>&nbsp;改变状态:
            </td>
            <td align="left" class="l-table-edit-td">
            <div id="changestatusradio" validate="{required:true}"></div>
                  
            </td>
            <td align="left">
            </td>
        </tr>*@
         
        <tr>
        <td align="right" class="l-table-edit-td">
                &nbsp;
            </td>
        <td align="left" colspan="2">
            <span id="lblmsg" class="l-validate-error">&nbsp;</span>
            <input type="hidden" name="processID" id="processID" value="0" />
        </td>
    </tr>
    </table>
</form>

<script type="text/javascript">
    var processgrid;
    var saveDialog;
    $(function () {
        //selType = $("#selType").ligerComboBox();

        $("#toptoolbar").ligerToolBar({ items: [{ text: '新增', click: grid_process_add, icon: "add" },
            { text: '修改', click: grid_process_edit, icon: "modify" },
            { text: '删除', click: grid_process_delete, icon: "delete" },
            { text: '刷新', click: grid_process_refresh, icon: "refresh" },
            { text: '返回', click: grid_process_back, icon: "prev" }
            ]
        });
        processgrid = $("#processgrid").ligerGrid({
            columns: [
                { display: '节点名称', name: 'ProcessName', width: '30%', isSort: false },
                { display: '办理类型', name: 'SignType', width: '20%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.SignType) == 0) { return '单一审批'; }
                        else if (parseInt(item.SignType) == 1) { return '多人并行审批'; }
                        return '多人审批一人认可';
                    }
                }, 
                { display: '办理人', name: 'SignUsers', width: '10%', isSort: false,
                    render: function (item) {
                         
                        return item.user.RealName;
                    }
                },
//                { display: '改变状态', name: 'ChangeState', width: '10%', isSort: false,
//                    render: function (item) {
//                        if (parseInt(item.ChangeState) == 1) return '审核中';
//                        return '审核完成';
//                    }
//                },
                { display: '状态', name: 'Status', width: '10%', isSort: false,
                    render: function (item) {
                        if (parseInt(item.Status) == 1) return '正常';
                        return '禁用';
                    }
                },
                {
                    display: '操作', isAllowHide: false,
                    render: function (row) {

                        var html = '<a href="#" onclick="grid_process_show(\'' + row.ProcessName + '\',\'' + row.SignType + '\',\'' + row.ChangeState + '\',\'' + row.SignUsers + '\',\'' + row.ID + '\')">修改</a>&nbsp;&nbsp;<a href="#" onclick="process_delete(\'' + row.ID + '\',\'' + row.ProcessName + '\')">删除</a>';
                         
                        return html;
                    }
                }
                ],
            width: '100%', height: '100%', rownumbers: true,
            dataAction: 'server',
            url: "/Process/GetProcessListByPageAndDefID?defID="+@processDef.ID,
            pageSizeOptions: [10],
            pageSize: 10
        });
        $.metadata.setType("attr", "validate");
        var v = $("#frmProcess").validate({
            //debug: true,
            errorPlacement: function (lable, element) {
                if (element.hasClass("l-textarea")) {
                    element.ligerTip({ content: lable.html(), target: element[0] });
                }
                else if (element.hasClass("l-text-field")) {
                    element.parent().ligerTip({ content: lable.html(), target: element[0] });
                }
                else {
                    lable.appendTo(element.parents("td:first").next("td"));
                }
            },
            success: function (lable) {
                lable.ligerHideTip();
                lable.remove();
            },
            submitHandler: function () {
                var signType = liger.get("signtyperadio").getValue();
                //var changeState = liger.get("changestatusradio").getValue();
                var signUsers = liger.get("singUser").getValue();
                 if ($('#txtProcessName').val() == "") {
                    $('#txtProcessName').focus();
                    $("#lblmsg").html('节点名称不能为空');
                    return;
                }
                if (liger.get("singUser").getValue() == "") {
                    $('#singUser').focus();
                    $("#lblmsg").html('请选择审批人');
                    return;
                }
                $.ajax({
                    url: "/Process/ProcessSave",
                    data: "processDefID=" + $("#processdefID").val() + "&processName=" + $('#txtProcessName').val() + "&signType=" + signType
                    + "&signUsers=" + signUsers + "&changeState=1&processID=" + $("#processID").val(),
                    type: "post",
                    success: function (result) {
                        //写提交ajax操作
                        if (result == "1") {
                            $.ligerDialog.success("保存成功。");
                            process_reset();
                            saveDialog.hide();
                            grid_process_refresh();
                        }
                        else {
                            if (result == "-1") {
                                $.ligerDialog.error("流程节点已存在!");
                            }
                            else {
                                $.ligerDialog.error("保存失败。");
                            }
                        }

                    }
                });
            }
        });
        $("#frmProcess").ligerForm();
    }); 
</script>